package cn.xs.home.action;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import javax.annotation.Resource;

import org.apache.struts2.ServletActionContext;

import cn.xs.goods.entity.Good;
import cn.xs.goods.service.GoodService;

import com.opensymphony.xwork2.ActionSupport;

/**
 * 首页控制器
 * @author xs
 *
 */
public class HomeAction extends ActionSupport {

	@Resource
	GoodService goodService;
	//跳转到首页、顺路带猜你喜欢商品过去
	public String toHomePageUI(){
		List<Good> goods = goodService.findAllByCategory("838753e0-70c3-4818-97e8-8942b9b9e03e");
		List<Good> items = new ArrayList<Good>();
		int len = goods.size();
		Random random = new Random();
		int count = 0;
		int tmp =0;
		while(count<4){
			tmp = random.nextInt(len);
			items.add(goods.remove(tmp));
			count++;
			len--;
		}
		ServletActionContext.getRequest().setAttribute("items", items);
		return "homepage";
	}
}
